public class Test6 {
    public static void main(String[] args) {
        Object A=new Object();
        Object B=new Object();
        Thread t1=new Thread(()->{
            synchronized (A){
                // 确保线程t2可以获取到锁B
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (B){
                    System.out.println("t1拿到了两把锁");
                }
            }
        });
        Thread t2=new Thread(()->{
            synchronized (A){
                //确保线程t1可以获取到锁A
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (B){
                    System.out.println("t2拿到了两把锁");
                }
            }
        });
        t1.start();
        t2.start();
    }
}
